package com.knowif.backend.controller;


import com.knowif.backend.dto.TUserDto;
import com.knowif.backend.service.WechatMiniUserService;
import com.knowif.system.model.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wechat")
public class WechatMiniController {

    @Autowired
    private WechatMiniUserService wechatMiniUserService;

	@PostMapping("/login")
    public RestBean<?> wechatLogin(@RequestBody TUserDto tUserDto){
        if(StringUtils.isEmpty(tUserDto.getCode())){
            return new RestBean<Object>(RestBean.bad_code, "code不能为空");
        }
        return wechatMiniUserService.wechatMiniLogin(tUserDto);
    }

    /**
     * 首页数据展示
     * @return
     */
    @GetMapping("/index")
    public RestBean<?> index(){
        return wechatMiniUserService.getIndexInfos();
    }

    /**
     * 发现页导师展示
     * @return
     */
    @GetMapping("/found")
    public RestBean<?> found(){
        return wechatMiniUserService.getFoundInfos();
    }

    /**
     * 快问页导师展示
     * @return
     */
    @GetMapping("/fastAsk")
    public RestBean<?> fastAsk(){
        return wechatMiniUserService.getFastAskInfos();
    }

    @PostMapping("/updateUnionInfo")
    public RestBean updateUnionInfo(@RequestBody String code){
        if(StringUtils.isEmpty(code)){
            return RestBean.buildError("code为空");
        }
        String result = wechatMiniUserService.updateUnionInfo(code);
        if(StringUtils.isEmpty(result)){
            return RestBean.buildError("未关注公众号");
        }
        return RestBean.buildSuccess(result,0);
    }

}
